package com.xing.fragment;

import java.util.List;
import com.xing.adapter.UploadListAdapter;
import com.xing.controller.DBController;
import com.xing.model.HsdModelSurvey;
import com.xing.my_interface.CallBack;
import com.xing.questionnairesurvey.R;
import com.xing.util.CurrentUserUtil;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

public class UploadFragment extends SuperFragment implements CallBack{
	
	private ListView uploadListView;
	private View view;
	private FragmentManager fragmentManager; 
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		fragmentManager = getFragmentManager();
		return (view = inflater.inflate(R.layout.upload_fragment, container, false));
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		userNameTextView = (TextView) view.findViewById(R.id.user_name);
		userNameTextView.setText(CurrentUserUtil.userName+",欢迎使用!");
		uploadListView = (ListView) view.findViewById(R.id.upload_listview);
		
		DBController.getInstance().getHsdModelSurveyList(getActivity(), getsurveyListHandler);
	}
	
	private Handler getsurveyListHandler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			List<HsdModelSurvey> hsdModelSurveysList = (List<HsdModelSurvey>) msg.obj;
			UploadListAdapter adapter = new UploadListAdapter(getActivity(), hsdModelSurveysList,fragmentManager,UploadFragment.this);
			uploadListView.setAdapter(adapter);
			adapter.notifyDataSetChanged();
			
		}
	};

	@Override
	public void fresh() {
		// TODO Auto-generated method stub
		DBController.getInstance().getHsdModelSurveyList(getActivity(), getsurveyListHandler);
	}
}
